package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 注册用户
     *
     * @param user
     * @return
     */
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    // 设置useGeneratedKeys和keyProperty 返回自增的主键 id
    @Insert("insert into user (openid,name,phone,sex,id_number,avatar,create_time) values (#{openid},#{name},#{phone},#{sex},#{idNumber},#{avatar},#{createTime})")
    void save(User user);


    /**
     * 通过 openid 查找用户
     * @param openid
     */
    @Select("select * from user where openid = #{openid}")
    User getUserByOpenid(String openid);

    /**
     * 通过 user id 查找用户
     * @param userId
     */
    @Select("select * from user where id = #{userId}")
    User getUserById(Long userId);
}
